using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace stringconversions.tests
{
    [TestFixture]
    public class test_SplitConfigIntoSettings
    {
        [Test]
        public void with_single_setting()
        {
            var settings = StringConversions.SplitConfigIntoSettings(new Configuration {Settings = "a"});

            Assert.AreEqual("a", settings.First().ParameterValuePair);
        }

        [Test]
        public void with_multiple_settings()
        {
            var settings = StringConversions.SplitConfigIntoSettings(new Configuration { Settings = "a;b" });

            Assert.AreEqual(new[]{"a", "b"}, settings.Select(s => s.ParameterValuePair).ToArray());
        }

        
        [Test]
        public void with_empty_config_leading_to_empty_dict()
        {
            var settings = StringConversions.SplitConfigIntoSettings(new Configuration { Settings = "" });

            Assert.AreEqual(new Setting[0], settings.Select(s => s.ParameterValuePair).ToArray());
        }


        [Test]
        public void keeping_whitespace_around_settings()
        {
            var settings = StringConversions.SplitConfigIntoSettings(new Configuration { Settings = " a ;  b  " });

            Assert.AreEqual(new[] { " a ", "  b  " }, settings.Select(s => s.ParameterValuePair).ToArray());
        }


        [Test]
        public void discarding_empty_settings()
        {
            var settings = StringConversions.SplitConfigIntoSettings(new Configuration { Settings = "a;;b" });

            Assert.AreEqual(new[] { "a", "b" }, settings.Select(s => s.ParameterValuePair).ToArray());
        }
    }
}